home *** CD-ROM | disk | FTP | other *** search
-
- DOS and DONT'S -- Part 22
- ==========================
-
- by Jimmy Weiler
-
-
-
-
- Now, let's look at the actual BASIC
-
- code that might be used to write the
-
- name and number into any record.
-
-
- 100 PRINT#3,NAME$
- 120 PRINT#3,NUMBER$
-
-
- (There's more to it than that, but
- we're not ready for the full
- technique just yet.)
-
-
- Line 100 prints "SCHLABOTNIK" followed
-
- by a carriage return. Line 120 prints
-
- "8687247" followed by a carriage
-
- return. Both fields AND both carriage
-
- returns will be written into the file,
-
- so when we determine our record size,
-
- it will have to be the sum of the
-
- maximum lengths of the each of the
-
- fields plus the number of fields.
-
- In our case, the desired record
-
- length would be 11 + 7 + 2 = 20.
-
- (That's eleven characters in the NAME
-
- field, seven characters in the NUMBER
-
- field, and a total of two fields.)
-
- Any record length greater than 20
-
- would also work, but would waste space
-
- on the disk. Let's stick with our
-
- record length of 89 -- we may decide
-
- later that we want to store more
-
- information than just names and phone
-
- numbers... or someone called Vladimir
-
- Byrzschynscvylmynschmylnovsky may
-
- join the class.
-
-
- --------------------
-
-
- That's how you open a REL file THE
-
- FIRST TIME. When you open a RELative
-
- file that already exists, you don't
-
- need to use the LENGTH parameter --
-
- the syntax is the same as for a SEQ
-
- file. If you want, you CAN specify
-
- the record length, but if you use the
-
- wrong length you will get an error 50,
-
- RECORD NOT PRESENT.
-
-
- --------------------
-
-
- When you OPEN a disk file, the
-
- parameters must all be contained in a
-
- single string. In RELative files,
-
- those are the NAME and LENGTH
-
- parameters. In other types, they are
-
- the NAME, TYPE, and MODE parameters.
-
- (Type is SEQ, PRG, or USR. Mode is
-
- READ or WRITE.) To make a single
-
- string, the individual parameters are
-
- CONCATENATED with the BASIC symbol
-
- "+". If your file name, "PHONEFILE"
-
- was stored in the variable FILE$, and
-
- your record length was stored in the
-
- variable L$, you could open a file
-
- like this:
-
-
- 10 FILE$ = "PHONEFILE"
- 20 L$ = CHR$(89)
- 30 OPEN 3,8,4,FILE$+",L,"+L$
-
-
- Or you could do the concatenation
-
- first:
-
-
- 10 F$ = "PHONEFILE,L,"+CHR$(89)
- 30 OPEN 3,8,4,F$
-
-
- Or you could put EVERYTHING between
-
- the quotes. Did you know that
-
- CHR$(89) is the letter "Y"?
-
-
- 30 OPEN 3,8,4,"PHONEFILE,L,Y"
-
-
- Of course, this third technique is
-
- enormously confusing when you look at
-
- your code later and try to figure out
-
- what record length "Y" will produce.
-
- I don't recommend it.
-
- -----------------
-
- Let's look at that "bug" I mentioned
-
- earlier -- record lengths of 58 are
-
- not allowed. Well, as you may know,
-
- CHR$(58) is the colon. You have
-
- probably also seen statements like
-
- this: OPEN 15,8,15,"S0:SCRATCHFILE".
-
- This is the DOS command to SCRATCH
-
- (remove) the file named "SCRATCHFILE"
-
- from disk drive 0. Most of us don't
-
- have a drive 1, but the 0 is still
-
- required for many commands. The point
-
- is that the COLON is the special
-
- character used to separate a DOS
-
- command from the filename upon which
-
- it is supposed to act.
-
- Another syntax for opening our REL
-
- file with a record length of 89 is:
-
- OPEN 3,8,4,"0:PHONEFILE,L,Y". If the
-
- record length was 58, the parameters
-
- would be "0:PHONEFILE,L,:". The
-
- second colon is obviously in the wrong
-
- place, and DOS knows it, thus the
-
- SYNTAX ERROR.
-
-
- -------- Continued in Part 23 --------
-